home *** CD-ROM | disk | FTP | other *** search
- Path: sun001.spd.dsccc.com!sun001!dthornto
- From: dthornto@aplo266.spd.dsccc.com (Duane Thornton)
- Newsgroups: comp.lang.c++
- Subject: Re: help on syntax
- Date: 03 Jan 1996 14:51:03 GMT
- Organization: none
- Message-ID: <DTHORNTO.96Jan3085103@aplo266.spd.dsccc.com>
- References: <96002.222728APCCU@CUNYVM.CUNY.EDU>
- NNTP-Posting-Host: aplo266.spd.dsccc.com
- In-reply-to: Paul Abrilla's message of Tue, 2 Jan 1996 22:27:28 EST
-
- You are using the wrong syntax for the 'if' statement. The correct
- syntax for 'if' is:
-
- if (expression)
- statement1;
- else
- statement2;
-
- Indentation does not force the statements following the 'if' to be
- part of statement1. You must enclose the statements in braces to force
- the proper association.
-
- if (expression)
- {
- statement1;
- statement2;
- .
- .
- .
- }
- else
- {
- statement11;
- statement12;
- .
- .
- .
- }
-
- >>>>> On Tue, 2 Jan 1996 22:27:28 EST, Paul Abrilla <APCCU@CUNYVM.CUNY.EDU> said:
-
- [Snip]
-
- Paul> PROGRAM I
-
- Paul> #include <iostream.h>
- #include <stdlib.h>
- ^^^^^^^^^^^^^^^^^^^ To get return value
- Paul> void main()
- ^^^^ change to 'int main()'
- Paul> {
- Paul> int a, b, c;
- Paul> cout << "Please enter three numbers¢n";
- Paul> cout << "a: ";
- Paul> cin >> a;
- Paul> cout << "¢nb: ";
- Paul> cin >> b;
- Paul> cout << "¢nc: ";
- Paul> cin >> c;
- Paul>
- Paul> if (c = (a-b))
- ^^^ change to '==' to test for equality
- {
- ^^^ add a brace
- Paul> cout << "a: ";
- Paul> cout << a;
- Paul> cout << " minus b: ";
- Paul> cout << b;
- Paul> cout << " quals c: ";
- ^^ typo?
- Paul> cout << c << endl;
- }
- ^^^ add a brace
- Paul> else
- Paul> cout << "a-b does not equal c: " << endl;
- Paul>
- return EXIT_SUCCESS;
- ^^^^^^^^^^^^^^^^^^^^ return value
- Paul> }
-
-
- [Snip]
-
- Paul> ----------- Paul email: apccu@cunyvm.cuny.edu
-
-
- --
- Duane
-
- ---------------------------- Duane Thornton --------------------------------
- Internet: dthornto@spd.dsccc.com Opinions are my own.
- DSC Communications Corporation Addr: MS 153, 1000 Coit Rd, Plano, TX 75075
- ----------------------------------------------------------------------------
- --
- Duane Thornton x94916
-
- ---------------------------- Duane Thornton --------------------------------
- Internet: dthornto@spd.dsccc.com Opinions are my own.
- DSC Communications Corporation Addr: MS 153, 1000 Coit Rd, Plano, TX 75075
- ----------------------------------------------------------------------------
-